﻿using System;

namespace DoNetTool.Common
{
    /// <summary>
    /// 签名参数抽象类
    /// </summary>
    public abstract class SignatureBase
    {
        /// <summary>
        /// 服务器分配的key
        /// </summary>
        public string AppKey { get; set; }

        /// <summary>
        /// 签名
        /// </summary>
        public string Signature { get; set; }

        /// <summary>
        /// 时间戳，请求时间,格式：年-月-日 时:分:秒
        /// </summary>
        public string Timestamp { get; set; }

        /// <summary>
        /// 验证时间戳，与当前时间相差10秒内
        /// </summary>
        /// <returns></returns>
        public bool ValidateTimestamp()
        {
            DateTime dtTimestamp = DateTime.Now;// DateTime.Parse(parameter.Timestamp);
            if (!DateTime.TryParse(Timestamp, out dtTimestamp))
            {
                return false;
            }
            if ((dtTimestamp - DateTime.Now).TotalSeconds > 10 || (DateTime.Now - dtTimestamp).TotalSeconds > 10)
            {
                return false;
            }
            return true;
        }
    }

    /// <summary>
    /// 参数验证结构
    /// </summary>
    public class ValidateValue
    {
        /// <summary>
        /// 参数值，必填
        /// </summary>
        public string Value { get; set; }
        /// <summary>
        /// 参数名称，必填
        /// </summary>
        public string CName { get; set; }

        /// <summary>
        /// 参数值范围(1,2,3)或
        /// 参数长度(2-10)
        /// </summary>
        public string RangeList { get; set; }

    }
}
